﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace WebBase
{
    public class ReqHelper
    {
        private static string TupleToString(Tuple<string, string> kv)
        {
            return kv.Item1 + "=" + kv.Item2;
        }
        public static string BuildUrl(string baseurl, params Tuple<string, string>[] kvs)
        {
            var ps = kvs.Select(kv => TupleToString(kv))
                .Aggregate((l, r) => l + "&" + r);
            return baseurl + "?" + ps;
        }
        public static string ReqGET(string url)
        {
            var req = WebRequest.Create(url);
            var s = req.GetResponse().GetResponseStream();
            using (var sr = new StreamReader(s))
            {
                return sr.ReadToEnd();
            }
        }
    }
}
